﻿Imports System.Windows.Forms
Imports ArfaUI

Public Class ListBankPage
    Inherits PageTemplate
    Private Sub setgrid()
        Dim dt As New DataTable
        DGVjnsobat.DataSource = Nothing
        If Utils.executeSP("proc_master_bank", New Object() {"select", "A"}, dt) Then
            If dt IsNot Nothing Then
                If dt.Rows.Count > 0 Then
                    DGVjnsobat.DataSource = dt
                End If
            End If
        End If
    End Sub
    Private Sub exec_data(ByVal exec As String)
        Dim dt As New DataTable
        If Utils.executeSP("proc_master_bank", New Object() {exec, TxtNama.Text}, dt) Then
            If dt IsNot Nothing Then
                If dt.Rows.Count > 0 Then
                    Utils.getmessagesystem(0, dt.Rows(0)(0))
                End If
            End If
        End If
    End Sub
    Private Sub setbuttononoff(Optional ByVal vsetmode As String = "on")
        If vsetmode = "on" Then
            btnAdd.Enabled = True
            'btnEdit.Enabled = True
            btnDel.Enabled = True
            btnAdd.Text = "Add"
            'btnEdit.Text = "Edit"
            btnDel.Text = "Delete"
        ElseIf vsetmode = "off" Then
            btnAdd.Enabled = False
            'btnEdit.Enabled = False
            btnDel.Enabled = False
            btnAdd.Text = "Add"
            'btnEdit.Text = "Edit"
            btnDel.Text = "Delete"
        End If
    End Sub

    Private Sub setbutton(Optional ByVal vtransmode As String = "clear")
        If vtransmode = "clear" Then
            setbuttononoff()
        ElseIf vtransmode = "Add" Then
            setbuttononoff("off")
            btnAdd.Enabled = True
            btnAdd.Text = "Save"
            'ElseIf vtransmode = "Edit" Then
            '    setbuttononoff("off")
            '    btnEdit.Enabled = True
            '    btnEdit.Text = "Save"
        ElseIf vtransmode = "Delete" Then
            setbuttononoff("off")
            btnDel.Enabled = True
            btnDel.Text = "Save"
        End If
    End Sub

    Private Sub ListBankPage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        setgrid()
        TxtNama.Text = String.Empty
        setbutton()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If btnAdd.Text = "Add" Then
            setbutton(btnAdd.Text)
            DGVjnsobat.Enabled = False
            PanEntry.Enabled = True
            TxtNama.Text = ""
            'isicombo()
            'ComboJenis.Focus()
        Else
            If TxtNama.Text = String.Empty Then
                MsgBox("Nama Bank Belum Diisi")
                Exit Sub
            Else
                If TxtNama.Text.Length > 100 Then
                    MsgBox("Nama Bank Melebihi Batas Karakter (max 100)")
                    Exit Sub
                End If
            End If

            exec_data("add")
            setgrid()
            setbutton()
            DGVjnsobat.Enabled = True
            PanEntry.Enabled = False
            TxtNama.Text = ""
        End If
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        If btnDel.Text = "Delete" Then
            setbutton(btnDel.Text)
            DGVjnsobat.Enabled = False
            PanEntry.Enabled = True
            'TxtNama.Text = ""
            'isicombo()
            'ComboJenis.Focus()
        Else
            If TxtNama.Text = String.Empty Then
                MsgBox("Nama Bank Belum Diisi")
                Exit Sub
            Else
                If TxtNama.Text.Length > 100 Then
                    MsgBox("Nama Bank Melebihi Batas Karakter (max 100)")
                    Exit Sub
                End If
            End If

            exec_data("delete")
            setgrid()
            setbutton()
            DGVjnsobat.Enabled = True
            PanEntry.Enabled = False
            TxtNama.Text = ""
        End If
    End Sub
    Private Sub DGVjnsobat_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVjnsobat.CellClick
        TxtNama.Text = DGVjnsobat.CurrentRow.Cells(0).Value
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        setgrid()
        setbutton()
        DGVjnsobat.Enabled = True
        PanEntry.Enabled = False
        TxtNama.Text = ""
    End Sub
End Class
